package cc.androidos;

import cc.androidos.commons.GlobalParameter;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;

public class DBUtil extends ContentProvider {
	
	private DatabaseHelper mOpenHelper;

	private static class DatabaseHelper extends SQLiteOpenHelper {
		DatabaseHelper(Context context) {
			super(context, GlobalParameter.DATABASE_NAME,null, GlobalParameter.DATABASE_VERSION);
		}
		
		@Override
		public void onCreate(SQLiteDatabase db) {}
		
		@Override
		public void onOpen(SQLiteDatabase db) {
			super.onOpen(db);
		}
			
		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
	}


	@Override
	public boolean onCreate() {
		mOpenHelper = new DatabaseHelper(getContext());
		return true;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		SQLiteDatabase db = mOpenHelper.getReadableDatabase();
		Cursor c = null;
		if(selection.equals(GlobalParameter.QUERY_TYPE_0)){
			c = db.rawQuery("SELECT word FROM "+GlobalParameter.TABLE_NAME+" WHERE word like ? Limit 100 ", projection);
		} else {
			c = db.rawQuery("SELECT TARGET_LANGURE FROM "+GlobalParameter.TABLE_NAME+" WHERE word = ?", projection);
		}
		
		return c;
	}
	


	@Override
	public String getType(Uri uri) {
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues initialValues) {
		return uri;
	}

	@Override
	public int delete(Uri uri, String where, String[] whereArgs) {
		return 0;
	}

	@Override
	public int update(Uri uri, ContentValues values, String where,
			String[] whereArgs) {
		return 0;
	}
}